﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Proc_GetHazardousLocations')
BEGIN
  DROP  Procedure  Proc_GetHazardousLocations
END
GO
CREATE Procedure Proc_GetHazardousLocations
    @PageIndex int,
	@PageSize int,
	@EnterpriseName varchar(200)	
AS
DECLARE @SQL nvarchar(1000)
DECLARE @RecordCount int,@P1 INT
DECLARE @Where VARCHAR(200)
IF @PageIndex <1 SET @PageIndex = 1
SET @PageIndex = (@PageIndex-1) * @PageSize + 1
IF ((@EnterpriseName IS NOT NULL) AND (RTRIM(LTRIM(@EnterpriseName))<>''))
BEGIN
  SET @Where = ' EnterpriseName LIKE ''%'+ @EnterpriseName + '%'''
END
SET @SQL = N'SELECT * FROM HazardousLocation_View  ORDER BY EnterpriseID'
IF (LEN(@Where)>0)
BEGIN
  SET @SQL = 'SELECT * FROM HazardousLocation_View WHERE ' + @Where + ' ORDER BY EnterpriseID'
END
EXEC sp_cursoropen @P1 OUTPUT, @SQL, @scrollopt = 1, @ccopt = 335873, @rowcount = @RecordCount OUTPUT 
IF (@P1 != 0)
BEGIN
  EXEC sp_cursorfetch @P1, 16, @PageIndex, @PageSize 
  EXEC sp_cursorclose @P1
END
select @RecordCount
return @@ERROR
GO


 